package com.yaoge.mvc.controller;

import com.yaoge.mvc.pojo.Employee;
import com.yaoge.mvc.pojo.User;
import org.springframework.http.RequestEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 用来测试报文信息转换器
 * 把请求报文转换成java对象
 * 把java对象 转换成响应报文
 */
@Controller
@RequestMapping("/converter")
public class TestMessageConverter {

    /**
     * 用来测试  RequestBody  注解
     * 可以把requestbody 的值放入到形参之中
     * @return
     */
    @RequestMapping("/body")
    public String testRequestBody(@RequestBody String requestBody){

        System.out.println("requestBody"+requestBody);
        return "success";
    }
 /**
     * 用来测试  RequesEnitty  注解
     * 可以把整个请求报文  转换成RequestEnitu   放入到形参之中  只是需要一个形参接收就可以了
     * @return
     */
    @RequestMapping("/enity")
    public String testRequestBody(RequestEntity<String> requestEntity){
        System.out.println("requestheader:"+requestEntity.getHeaders());
        System.out.println("requestBody:"+requestEntity.getBody());

        return "success";
    }

    /**
     * 加上@ResponseBody  其实就是说明这个类的返回值就是响应报文
     * 但是需要转换成json  还需要加上jackson的依赖
     * @return
     */
    @ResponseBody
    @RequestMapping("/responseBody")
    public Employee testResponseBody(){
        Employee employee = new Employee(10001, "ndj", "kdsjjad.mail", 1);


        return employee;
    }
    @ResponseBody
    @RequestMapping("/testAjax")
    public User testAjax(String username,String password){
        User user = new User(username, password, "男", 12, "dshdsu@gamil.com", "27182");


        return user;
    }





}
